package cn.tedu.modules;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @Author: Miyako
 * @Date: 2024-07-30-17:40
 * @Description: 实现注册功能
 */
public class JDBCRegiste {
    private Connection c;
    JDBCRegiste(Connection c){
        this.c = c;
    }
    public  void startRegiste(String username , String password,String nickname , int age ){
        try(PreparedStatement p= c.prepareStatement("insert into userinfo(username,password,nickname,age)values(?,?,?,?)")){
            p.setString(1,username);
            p.setString(2,password);
            p.setString(3,nickname);
            p.setInt(4,age);
            int i = p.executeUpdate();
            if (i==0){
                System.out.println("注册失败");
            }else {
                System.out.println("注册成功");
            }
        }catch (SQLException e){
           e.printStackTrace();
       }

    }

}
